<template>
	<view class="content">
		<view v-if="!changeSuccess">
			<view class="uni-form-item uni-column">
				<input type="tel" class="uni-input" name="" maxlength="11" placeholder="请输入手机号" />
			</view>
			<view class="uni-form-item uni-column column-with-btn">
				<input type="text" class="uni-input" maxlength="4" name="" placeholder="请输入图片验证码" v-model="captchaImg" />
				<image src="../../static/img/shuaxin.png" class="shuaxin"></image>
				<image src="../../static/img/captcha.jpg" mode="" class="img-captcha"></image>
			</view>
			<view class="uni-form-item uni-column column-with-btn">
				<input type="number" class="uni-input" maxlength="6" name="" placeholder="手机验证" />
				<button :class="{active : !disableCodeBtn}" :disabled="disableCodeBtn" @tap="sendCode">{{codeBtn.text}}</button>
			</view>
			<view class="uni-form-item uni-column">
				<input type="password" class="uni-input" name="" maxlength="16" minlength="6" placeholder="设置密码:6-16位密码" />
			</view>
			<button type="primary" @tap="changeSuccess = !changeSuccess">注册</button>
		</view>
		<view v-if="changeSuccess">
			<view class="text-reset">注册成功，点击去登陆！</view>
			<button type="primary" @tap="gotoLogin">立即登陆</button>
		</view>
	</view>
</template>

<script>
	export default {
		components:{
	
		        },
		data() {
			return {
				captchaImg: '',
				seconds: 59,
				codeBtn: {
					text: '发送验证码',
					waitingCode: false,
					count: this.seconds
				},
				changeSuccess: false
			}
		},
		onLoad() {

		},
		methods:{
				sendCode: function () {
				this.codeBtn.waitingCode = true;
				this.codeBtn.count = this.seconds;
				this.codeBtn.text = this.codeBtn.count + 's';
				
				let countdown = setInterval( () => {
					this.codeBtn.count--;
					this.codeBtn.text = this.codeBtn.count + 's';
					if( this.codeBtn.count < 0 ){
						clearInterval(countdown);
						this.codeBtn.text = '重新发送';
						this.codeBtn.waitingCode = false;
					}
				},1000);
			},
			gotoLogin: function () {
				uni.switchTab({
					url: ''
				});
			}
		},
		computed: {
			disableCodeBtn: function (){
				return this.codeBtn.waitingCode || this.captchaImg.length < 4;
			} 
		}
	}
</script>

<style lang="scss">
    page,.content{
        width: 100vw;
        min-height: 100vh;
        margin: 0;
        box-sizing: border-box;
    }
    .input-row{
        width: 600upx;
        margin: 0 auto;
        padding: 30upx 0;
        box-sizing: border-box;
        font-size: 24px;
        text-align: center;
        .item{
            float: left;
            width: 80upx;
            height: 80upx;
            line-height: 80upx;
            border-radius: 10upx;
            margin:0 10upx;
            border: 1px solid #C8C8C8;
            background: #fff;
            box-sizing: border-box;
        }
        .item-active{
            position: relative;
            border: 1px solid #f4000a;
            transform: scale(1.2);
            --webkit-transform: scale(1.2);
        }
}

//
	
	.shuaxin{
		width: 40upx;
		height: 30upx;
		padding-left:50upx ;
	}
	
	$color-primary: #b49950;
	.content{
		padding: 45px;
	}
	.uni-form-item{
		margin-bottom: 40upx;
		padding: 0;
		border-bottom: 1px solid #e3e3e3;
		.uni-input{
			font-size: 30upx;
			padding: 7px 0;
		}
	}
	.column-with-btn{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		button{
			font-size: 24upx;
			margin: 0;
			width: 180upx;
			text-align: center;
			&:after{
				border: none
			}
			&.active{
				background-color: $color-primary;
				color: $uni-text-color-inverse;
			}
		}
	}
	.img-captcha{
		width: 150upx;
		height: 60upx;
	}
	button[type="primary"]{
		background-color: rgba(51, 177, 123, 1);;
		border-radius: 1rem;
		font-size: 34upx;
		margin-top: 70upx;
		height: 90upx;
	}
	.text-reset{
		text-align: center;
		margin-bottom: 100upx;
		font-size: 36upx;
	}
</style>
